package com.algorithm.collection.spliterator;

import org.apache.commons.lang3.StringUtils;

import java.util.Spliterator;
import java.util.function.Consumer;

/**
 * 数字并行迭代器
 */
public class NumCounterSpliterator implements Spliterator<Character> {

    private String str;
    private int currentChar = 0;
    private boolean canSplit = true;

    public NumCounterSpliterator(int currentChar, String str, boolean canSplit) {
        this.str = str;
        this.currentChar = currentChar;
        this.canSplit = canSplit;
    }
    @Override
    public boolean tryAdvance(Consumer<? super Character> action) {

        if(StringUtils.isBlank(str)){
            return false;
        }
        //对对应的参数运行action操作
        action.accept(str.charAt(currentChar++));
        return currentChar < str.length();
    }

    @Override
    public Spliterator<Character> trySplit() {
        //当前索引
        int i=currentChar;
        for(;canSplit && currentChar < str.length();i++){
            if(!Character.isDigit(str.charAt(i))){

            }
        }
        return null;
    }

    @Override
    public long estimateSize() {
        return 0;
    }

    @Override
    public int characteristics() {
        return ORDERED | SIZED | SUBSIZED | NONNULL | IMMUTABLE;
    }


}
